package yuan.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;

public class BatchProducer {
    public static void main(String[] args) throws Exception{
        DefaultMQProducer producer = new DefaultMQProducer("batMessage");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();
        String topic = "TopicTest";

        ArrayList<Message> messages = new ArrayList<>();
        messages.add(new Message(topic, "TagA", "OrderID001", "Hello world 0".getBytes()));
        messages.add(new Message(topic, "TagA", "OrderID002", "Hello world 1".getBytes()));
        messages.add(new Message(topic, "TagA", "OrderID003", "Hello world 2".getBytes()));


        SendResult send = producer.send(messages);

        System.out.println(send.getMessageQueue());
        System.out.println(send.getSendStatus());
        System.out.println(send.getMsgId());
        System.out.println(send.getOffsetMsgId());
        System.out.println(send.getQueueOffset());
        producer.shutdown();
    }
}
